import { CoolController, BaseController, TagTypes, CoolUrlTag } from '@cool-midway/core';
import { Body, Inject, Post, Get, Query } from '@midwayjs/core';
import { MemberUserInfoEntity } from '../../entity/info';
import { MemberUserInfoService } from '../../service/info';

/**
 * member模块-用户信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: MemberUserInfoEntity,
  service: MemberUserInfoService,
  pageQueryOp: {
    keyWordLikeFields: ['username', 'nickname'],
    fieldEq: ['level', 'status'],
    where: async (ctx) => {
      return [['a.age > :age', { age: 18 }]];
    }
  }
})


@CoolUrlTag({
  key: TagTypes.IGNORE_TOKEN,
  value: ["orderTotal","totalSalesVolume"],
})


export class AdminMemberUserInfoController extends BaseController {
  @Inject()
  memberUserInfoService: MemberUserInfoService;

  @Post('/detail', { summary: '获取用户详情' })
  async detail(@Body('id') id: number) {
    return this.ok(await this.memberUserInfoService.info(id));
  }

  @Get('/orderTotal', { summary: '获取数量' })
  async orderTotal(@Query() BodyData: any) {
    return this.ok(await this.memberUserInfoService.orderTotal());
  }

  // 销售额
  @Get('/totalSalesVolume', { summary: '获取销售额' })
  async totalSalesVolume(@Query() BodyData: any) {
    return this.ok(await this.memberUserInfoService.totalSalesVolume());
  }

}
